/**
 * <p>Copyright: Copyright (c) 2014</p>
 * <p>Company: ---Technology Co. Ltd</p>
 * <p>2014-4-30</p>
 * @author Jan.Zhang
 */
package com.xianl.busiplat.shiro;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.xianl.busiplat.util.VerifyCodeUtil;


/** 
 * desc:
 * <p>author: Jan.Zhang </p>
 * date: 2014-4-30
 */
public class SimpleCaptchaServlet extends HttpServlet {

	/**
	 * long:serialVersionUID 
	 */
	private static final long serialVersionUID = 1093381233713902207L;
	
	private int height = 100;
	private int width = 30;
	private int length = 4;
	
	public static final String CAPTCHA_KEY = "captcha_key";
	
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		height = Integer
				.parseInt(getServletConfig().getInitParameter("height"));
		width = Integer.parseInt(getServletConfig().getInitParameter("width"));
	}

	protected void doGet(HttpServletRequest req, HttpServletResponse response) throws IOException, ServletException {
		if(length > 12 || length < 1 ) {
			length = 12;
		}
		VerifyCodeUtil.create(width, height, 2, CAPTCHA_KEY, req, response);
	}
}
